package org.jeecg.activiti.ActivitClass;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysUserMapper;

/**
 * @author UmizzZ
 * @date
 */
@Slf4j
public class UserInfoSetting implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution){
        log.info("用户基础信息设置");
        System.out.println("-----------userInfoSetting----------excuting-----------");
        SysUserMapper sysUserMapper = SpringContextHolder.getBean(SysUserMapper.class);
        String username = String.valueOf(execution.getVariable("username"));
        SysUser loginUser = sysUserMapper.selectOne(new QueryWrapper<SysUser>().eq("username", username));
//        JSONObject jsonObject = JSON.parseObject(String.valueOf(execution.getVariable("bpm$user")));
        Integer credit = loginUser.getCredit();
        Double balance = loginUser.getBalance();
        execution.setVariable("credit", credit);
        execution.setVariable("balance", balance);
    }
}